﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ExpressionCalculator
{
  /// <summary>
  /// Interaction logic for MainWindow.xaml
  /// </summary>
  public partial class MainWindow : Window
  {
    Calculator _calculator = new Calculator();

    public MainWindow()
    {
      InitializeComponent();
    }

    private void _btn0_Click(object sender, RoutedEventArgs e)
    {
        if (_calculator.Number1 == string.Empty)
            _calculator.Number1 = "0";
        else if (_calculator.Number2 == string.Empty)
            _calculator.Number2 = "0";
    }

    private void _btn1_Click(object sender, RoutedEventArgs e)
    {
      if (_calculator.Number1 == string.Empty)
        _calculator.Number1 = "1";
      else if (_calculator.Number2 == string.Empty)
        _calculator.Number2 = "1";
    }

    private void _btn2_Click(object sender, RoutedEventArgs e)
    {
      if (_calculator.Number1 == string.Empty)
        _calculator.Number1 = "2";
      else if (_calculator.Number2 == string.Empty)
        _calculator.Number2 = "2";
    }

    private void _btn3_Click(object sender, RoutedEventArgs e)
    {
        if (_calculator.Number1 == string.Empty)
            _calculator.Number1 = "3";
        else if (_calculator.Number2 == string.Empty)
            _calculator.Number2 = "3";
    }

    private void _btn4_Click(object sender, RoutedEventArgs e)
    {
        if (_calculator.Number1 == string.Empty)
            _calculator.Number1 = "4";
        else if (_calculator.Number2 == string.Empty)
            _calculator.Number2 = "4";
    }

    private void _btn5_Click(object sender, RoutedEventArgs e)
    {
        if (_calculator.Number1 == string.Empty)
            _calculator.Number1 = "5";
        else if (_calculator.Number2 == string.Empty)
            _calculator.Number2 = "5";
    }

    private void _btn6_Click(object sender, RoutedEventArgs e)
    {
        if (_calculator.Number1 == string.Empty)
            _calculator.Number1 = "6";
        else if (_calculator.Number2 == string.Empty)
            _calculator.Number2 = "6";
    }

    private void _btn7_Click(object sender, RoutedEventArgs e)
    {
        if (_calculator.Number1 == string.Empty)
            _calculator.Number1 = "7";
        else if (_calculator.Number2 == string.Empty)
            _calculator.Number2 = "7";
    }

    private void _btn8_Click(object sender, RoutedEventArgs e)
    {
        if (_calculator.Number1 == string.Empty)
            _calculator.Number1 = "8";
        else if (_calculator.Number2 == string.Empty)
            _calculator.Number2 = "8";
    }

    private void _btn9_Click(object sender, RoutedEventArgs e)
    {
        if (_calculator.Number1 == string.Empty)
            _calculator.Number1 = "9";
        else if (_calculator.Number2 == string.Empty)
            _calculator.Number2 = "9";
    }

    private void _btnPlus_Click(object sender, RoutedEventArgs e)
    {
      if(_calculator.CurrOperator == string.Empty)
        _calculator.CurrOperator = "+";
    }

    private void _btnMultiply_Click(object sender, RoutedEventArgs e)
    {
      if (_calculator.CurrOperator == string.Empty)
          _calculator.CurrOperator = "*";
    }

    private void _btnEnter_Click(object sender, RoutedEventArgs e)
    {
      _tbDisplay.Text = string.Format("{0} {1} {2} = {3}", _calculator.Number1, _calculator.CurrOperator, _calculator.Number2, _calculator.Result);

      // clean values
      _calculator.Reset();
    }
  }
}
